# coding:utf-8

from datetime import datetime
from datetime import timedelta

now = datetime.now()
print(now, type(now))  # 2022-07-19 14:16:24.123337 <class 'datetime.datetime'>
# 时间对象转字符串
now_str = now.strftime('%Y-%m-%d %H:%M:%S')
print(now_str, type(now_str))  # 2022-07-19 14:16:24 <class 'str'>

# 字符串转时间对象
now_obj = datetime.strptime(now_str, '%Y-%m-%d %H:%M:%S')
print(now_obj, type(now_obj))   # 2022-07-19 14:27:22 <class 'datetime.datetime'>


